home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DJGPP
/
BNU22DC.ZIP
/
docs
/
binutils
/
ld.i2
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1993-09-06
|
29KB
|
595 lines
This is Info file ld.info, produced by Makeinfo-1.52 from the input
file ./ld.texinfo.
START-INFO-DIR-ENTRY
* Ld: (ld). The GNU linker.
END-INFO-DIR-ENTRY
This file documents the GNU linker LD.
Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the entire resulting derived work is distributed under the terms
of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions.
File: ld.info, Node: BFD, Next: MRI, Prev: Commands, Up: Top
The linker accesses object and archive files using the BFD libraries.
These libraries allow the linker to use the same routines to operate on
object files whatever the object file format. A different object file
format can be supported simply by creating a new BFD back end and adding
it to the library. You can use `objdump -i' (*note objdump:
(binutils.info)objdump.) to list all the formats available for each
architecture under BFD. This was the list of formats, and of
architectures supported for each format, as of the time this manual was
prepared:
BFD header file version 0.18
a.out-i386
(header big endian, data big endian)
m68k:68020
a29k
sparc
i386
a.out-sunos-big
(header big endian, data big endian)
m68k:68020
a29k
sparc
i386
b.out.big
(header big endian, data little endian)
i960:core
b.out.little
(header little endian, data little endian)
i960:core
coff-a29k-big
(header big endian, data big endian)
a29k
coff-h8300
(header big endian, data big endian)
H8/300
coff-i386
(header little endian, data little endian)
i386
coff-Intel-big
(header big endian, data little endian)
i960:core
coff-Intel-little
(header little endian, data little endian)
i960:core
coff-m68k
(header big endian, data big endian)
m68k:68020
coff-m88kbcs
(header big endian, data big endian)
m88k:88100
ecoff-bigmips
(header big endian, data big endian)
mips
ecoff-littlemips
(header little endian, data little endian)
mips
elf-big
(header big endian, data big endian)
m68k:68020
vax
i960:core
a29k
sparc
mips
i386
m88k:88100
H8/300
rs6000:6000
elf-little
(header little endian, data little endian)
m68k:68020
vax
i960:core
a29k
sparc
mips
i386
m88k:88100
H8/300
rs6000:6000
ieee
(header big endian, data big endian)
m68k:68020
vax
i960:core
a29k
sparc
mips
i386
m88k:88100
H8/300
rs6000:6000
srec
(header big endian, data big endian)
m68k:68020
vax
i960:core
a29k
sparc
mips
i386
m88k:88100
H8/300
rs6000:6000
As with most implementations, BFD is a compromise between several
conflicting requirements. The major factor influencing BFD design was
efficiency: any time used converting between formats is time which
would not have been spent had BFD not been involved. This is partly
offset by abstraction payback; since BFD simplifies applications and
back ends, more time and care may be spent optimizing algorithms for a
greater speed.
One minor artifact of the BFD solution which you should bear in mind
is the potential for information loss. There are two places where
useful information can be lost using the BFD mechanism: during
conversion and during output. *Note BFD information loss::.
* Menu:
* BFD outline:: How it works: an outline of BFD
* BFD information loss:: Information Loss
* Mechanism:: Mechanism
File: ld.info, Node: BFD outline, Next: BFD information loss, Up: BFD
How it works: an outline of BFD
===============================
When an object file is opened, BFD subroutines automatically
determine the format of the input object file, and build a descriptor in
memory with pointers to routines that will be used to access elements of
the object file's data structures.
As different information from the the object files is required, BFD
reads from different sections of the file and processes them. For
example, a very common operation for the linker is processing symbol
tables. Each BFD back end provides a routine for converting between
the object file's representation of symbols and an internal canonical
format. When the linker asks for the symbol table of an object file, it
calls through the memory pointer to the BFD back end routine which
reads and converts the table into a canonical form. The linker then
operates upon the common form. When the link is finished and the linker
writes the symbol table of the output file, another BFD back end
routine is called which takes the newly created symbol table and
converts it into the chosen output format.
File: ld.info, Node: BFD information loss, Next: Mechanism, Prev: BFD outline, Up: BFD
Information Loss
================
*Information can be lost during output.* The output formats
supported by BFD do not provide identical facilities, and information
which may be described in one form has nowhere to go in another format.
One example of this is alignment information in `b.out'. There is
nowhere in an `a.out' format file to store alignment information on the
contained data, so when a file is linked from `b.out' and an `a.out'
image is produced, alignment information will not propagate to the
output file. (The linker will still use the alignment information
internally, so the link is performed correctly).
Another example is COFF section names. COFF files may contain an
unlimited number of sections, each one with a textual section name. If
the target of the link is a format which does not have many sections
(e.g., `a.out') or has sections without names (e.g., the Oasys format)
the link cannot be done simply. You can circumvent this problem by
describing the desired input-to-output section mapping with the command
language.
*Information can be lost during canonicalization.* The BFD internal
canonical form of the external formats is not exhaustive; there are
structures in input formats for which there is no direct representation
internally. This means that the BFD back ends cannot maintain all
possible data richness through the transformation between external to
internal and back to external formats.
This limitation is only a problem when using the linker to read one
format and write another. Each BFD back end is responsible for
maintaining as much data as possible, and the internal BFD canonical
form has structures which are opaque to the BFD core, and exported only
to the back ends. When a file is read in one format, the canonical form
is generated for BFD and the linker. At the same time, the back end
saves away any information which would otherwise be lost. If the data
is then written back in the same format, the back end routine will be
able to use the canonical form provided by the BFD core as well as the
information it prepared earlier. Since there is a great deal of
commonality between back ends, there is no information lost when
linking big endian COFF to little endian COFF, or from `a.out' to
`b.out'. When a mixture of formats is linked, the information is only
lost from the files whose format differs from the destination.
File: ld.info, Node: Mechanism, Prev: BFD information loss, Up: BFD
Mechanism
=========
The greatest potential for loss of information occurs when there is
the least overlap between the information provided by the source
format, that stored by the canonical format, and that needed by the
destination format. A brief description of the canonical form may help
you understand which kinds of data you can count on preserving across
conversions.
*files*
Information on target machine architecture, particular
implementation, and format type are stored on a per-file basis.
Other information includes a demand pagable bit and a write
protected bit. Information like Unix magic numbers is not stored
here--only the magic numbers' meaning, so a `ZMAGIC' file would
have both the demand pagable bit and the write protected text bit
set.
The byte order of the target is stored on a per-file basis, so
that big- and little-endian object files may be linked with one
another.
*sections*
Each section in the input file contains the name of the section,
the original address in the object file, various options, size and
alignment information and pointers into other BFD data structures.
*symbols*
Each symbol contains a pointer to the object file which originally
defined it, its name, its value, and various option bits. When a
BFD back end reads in a symbol table, the back end relocates all
symbols to make them relative to the base of the section where
they were defined. Doing this ensures that each symbol points to
its containing section. Each symbol also has a varying amount of
hidden private data for the BFD back end. Since the symbol points
to the original file, the private data format for that symbol is
accessible. `ld' can operate on a collection of symbols of wildly
different formats without problems.
Normal global and simple local symbols are maintained on output,
so an output file (no matter its format) will retain symbols
pointing to functions and to global, static, and common variables.
Some symbol information is not worth retaining; in `a.out', type
information is stored in the symbol table as long symbol names.
This information would be useless to most COFF debuggers and may
be thrown away with appropriate command line switches. (The GNU
debugger `gdb' does support `a.out' style debugging information in
COFF).
There is one word of type information within the symbol, so if the
format supports symbol type information within symbols (for
example, COFF, IEEE, Oasys) and the type is simple enough to fit
within one word (nearly everything but aggregates), the
information will be preserved.
*relocation level*
Each canonical BFD relocation record contains a pointer to the
symbol to relocate to, the offset of the data to relocate, the
section the data is in, and a pointer to a relocation type
descriptor. Relocation is performed by passing messages through
the relocation type descriptor and the symbol pointer. Therefore,
relocations can be performed on output data using a relocation
method that is only available in one of the input formats. For
instance, Oasys provides a byte relocation format. A relocation
record requesting this relocation type would point indirectly to a
routine to perform this, so the relocation may be performed on a
byte being written to a COFF file, even though 68k COFF has no
such relocation type.
*line numbers*
Object formats can contain, for debugging purposes, some form of
mapping between symbols, source line numbers, and addresses in the
output file. These addresses have to be relocated along with the
symbol information. Each symbol with an associated list of line
number records points to the first record of the list. The head
of a line number list consists of a pointer to the symbol, which
allows finding out the address of the function whose line number
is being described. The rest of the list is made up of pairs:
offsets into the section and line numbers. Any format which can
simply derive this information can pass it successfully between
formats (COFF, IEEE and Oasys).
File: ld.info, Node: MRI, Next: Index, Prev: BFD, Up: Top
MRI Compatible Script Files
***************************
To aid users making the transition to GNU `ld' from the MRI linker,
`ld' can use MRI compatible linker scripts as an alternative to the
more general-purpose linker scripting language described in *Note
Command Language: Commands. MRI compatible linker scripts have a much
simpler command set than the scripting language otherwise used with
`ld'. GNU `ld' supports the most commonly used MRI linker commands;
these commands are described here.
You can specify a file containing an MRI-compatible script using the
`-c' command-line option.
Each command in an MRI-compatible script occupies its own line; each
command line starts with the keyword that identifies the command (though
blank lines are also allowed for punctuation). If a line of an
MRI-compatible script begins with an unrecognized keyword, `ld' issues
a warning message, but continues processing the script.
Lines beginning with `*' are comments.
You can write these commands using all upper-case letters, or all
lower case; for example, `chip' is the same as `CHIP'. The following
list shows only the upper-case form of each command.
`ABSOLUTE SECNAME'
`ABSOLUTE SECNAME, SECNAME, ... SECNAME'
Normally, `ld' includes in the output file all sections from all
the input files. However, in an MRI-compatible script, you can
use the `ABSOLUTE' command to restrict the sections that will be
present in your output program. If the `ABSOLUTE' command is used
at all in a script, then only the sections named explicitly in
`ABSOLUTE' commands will appear in the linker output. You can
still use other input sections (whatever you select on the command
line, or using `LOAD') to resolve addresses in the output file.
`ALIAS OUT-SECNAME, IN-SECNAME'
Use this command to place the data from input section IN-SECNAME
in a section called OUT-SECNAME in the linker output file.
IN-SECNAME may be an integer.
`BASE EXPRESSION'
Use the value of EXPRESSION as the lowest address (other than
absolute addresses) in the output file.
`CHIP EXPRESSION'
`CHIP EXPRESSION, EXPRESSION'
This command does nothing; it is accepted only for compatibility.
`END'
This command does nothing whatever; it's only accepted for
compatibility.
`FORMAT OUTPUT-FORMAT'
Similar to the `OUTPUT_FORMAT' command in the more general linker
language, but restricted to one of these output formats:
1. S-records, if OUTPUT-FORMAT is `S'
2. IEEE, if OUTPUT-FORMAT is `IEEE'
3. COFF (the `coff-m68k' variant in BFD), if OUTPUT-FORMAT is
`COFF'
`LIST ANYTHING...'
Print (to the standard output file) a link map, as produced by the
`ld' command-line option `-M'.
The keyword `LIST' may be followed by anything on the same line,
with no change in its effect.
`LOAD FILENAME'
`LOAD FILENAME, FILENAME, ... FILENAME'
Include one or more object file FILENAME in the link; this has the
same effect as specifying FILENAME directly on the `ld' command
line.
`NAME OUTPUT-NAME'
OUTPUT-NAME is the name for the program produced by `ld'; the
MRI-compatible command `NAME' is equivalent to the command-line
option `-o' or the general script language command `OUTPUT'.
`ORDER SECNAME, SECNAME, ... SECNAME'
`ORDER SECNAME SECNAME SECNAME'
Normally, `ld' orders the sections in its output file in the order
in which they first appear in the input files. In an
MRI-compatible script, you can override this ordering with the
`ORDER' command. The sections you list with `ORDER' will appear
first in your output file, in the order specified.
`PUBLIC NAME=EXPRESSION'
`PUBLIC NAME,EXPRESSION'
`PUBLIC NAME EXPRESSION'
Supply a value (EXPRESSION) for external symbol NAME used in the
linker input files.
`SECT SECNAME, EXPRESSION'
`SECT SECNAME=EXPRESSION'
`SECT SECNAME EXPRESSION'
You can use any of these three forms of the `SECT' command to
specify the start address (EXPRESSION) for section SECNAME. If
you have more than one `SECT' statement for the same SECNAME, only
the *first* sets the start address.
File: ld.info, Node: Index, Prev: MRI, Up: Top
Index
*****
* Menu:
* ": Symbols.
* ( COMMON ): Section Contents.
* *(SECTION): Section Contents.
* -b FORMAT: Invocation.
* -Bstatic: Invocation.
* -c MRI-CMDFILE: Invocation.
* -d: Invocation.
* -dc: Invocation.
* -defsym SYMBOL=EXP: Invocation.
* -dp: Invocation.
* -e ENTRY: Invocation.
* -F: Invocation.
* -format: Invocation.
* -g: Invocation.
* -i: Invocation.
* -lAR: Invocation.
* -LDIR: Invocation.
* -m: Invocation.
* -M: Invocation.
* -n: Invocation.
* -N: Invocation.
* -noinhibit-exec: Invocation.
* -o OUTPUT: Invocation.
* -r: Invocation.
* -R FILE: Invocation.
* -relax: Invocation.
* -S: Invocation.
* -s: Invocation.
* -t: Invocation.
* -T SCRIPT: Invocation.
* -Tbss BSSORG: Invocation.
* -Tdata DATAORG: Invocation.
* -Ttext TEXTORG: Invocation.
* -u SYM: Invocation.
* -Ur: Invocation.
* -v: Invocation.
* -X: Invocation.
* -x: Invocation.
* -ySYMBOL: Invocation.
* .: Location Counter.
* 0x: Integers.
* ;: Assignment.
* =FILL: Section Options.
* >REGION: Section Options.
* ABSOLUTE (MRI): MRI.
* ALIAS (MRI): MRI.
* BASE (MRI): MRI.
* CHIP (MRI): MRI.
* END (MRI): MRI.
* FORMAT (MRI): MRI.
* LIST (MRI): MRI.
* LOAD (MRI): MRI.
* NAME (MRI): MRI.
* ORDER (MRI): MRI.
* PUBLIC (MRI): MRI.
* SECT (MRI): MRI.
* FILENAME: Section Contents.
* FILENAME(SECTION): Section Contents.
* SYMBOL = EXPRESSION ;: Section Contents.
* SYMBOL F= EXPRESSION ;: Section Contents.
* { SCRIPT }: Invocation.
* absolute and relocatable symbols: Assignment.
* ABSOLUTE(EXP): Built-ins.
* ADDR(SECTION): Built-ins.
* ALIGN(EXP): Built-ins.
* aligning sections: Section Options.
* allocating memory: MEMORY.
* architectures available: BFD.
* archive files, from cmd line: Invocation.
* arithmetic: Expressions.
* arithmetic operators: Operators.
* assignment in scripts: Assignment.
* assignment, in section defn: Section Contents.
* back end: BFD.
* BFD canonical format: Mechanism.
* BFD requirements: BFD.
* binary input files: Other Commands.
* binary input format: Invocation.
* BLOCK(ALIGN): Section Options.
* BYTE(EXPRESSION): Section Contents.
* command files: Commands.
* command line: Invocation.
* commands, fundamental: Scripts.
* comments: Scripts.
* common allocation: Invocation.
* common allocation: Other Commands.
* commons in output: Section Contents.
* compatibility, MRI: Invocation.
* constructors: Invocation.
* contents of a section: Section Contents.
* CREATE_OBJECT_SYMBOLS: Section Contents.
* current output location: Location Counter.
* decimal integers: Integers.
* DEFINED(SYMBOL): Built-ins.
* deleting local symbols: Invocation.
* direct output: Section Contents.
* discontinuous memory: MEMORY.
* dot: Location Counter.
* entry point, defaults: Entry Point.
* entry point, from command line: Invocation.
* ENTRY(SYMBOL): Entry Point.
* expression evaluation order: Evaluation.
* expression syntax: Expressions.
* expression, absolute: Built-ins.
* filename symbols: Section Contents.
* files and sections, section defn: Section Contents.
* files, including in output sections: Section Contents.
* fill pattern, entire section: Section Options.
* FILL(EXPRESSION): Section Contents.
* first input file: Other Commands.
* first instruction: Entry Point.
* FLOAT: Other Commands.
* FORCE_COMMON_ALLOCATION: Other Commands.
* format, output file: Other Commands.
* formats available: BFD.
* functions in expression language: Built-ins.
* fundamental script commands: Scripts.
* GNU linker: Overview.
* GNUTARGET: Other Commands.
* header size: Built-ins.
* hexadecimal integers: Integers.
* holes: Location Counter.
* holes, filling: Section Contents.
* incremental link: Invocation.
* INPUT ( FILES ): Other Commands.
* input file format: Other Commands.
* input filename symbols: Section Contents.
* input files, displaying: Invocation.
* input files, section defn: Section Contents.
* input format: Invocation.
* input format: Invocation.
* input sections to output section: Section Contents.
* integer notation: Integers.
* integer suffixes: Integers.
* internal object-file format: Mechanism.
* K and M integer suffixes: Integers.
* l =: MEMORY.
* L, deleting symbols beginning: Invocation.
* layout of output file: Scripts.
* lazy evaluation: Evaluation.
* len =: MEMORY.
* LENGTH =: MEMORY.
* link map: Invocation.
* local symbols, deleting: Invocation.
* location counter: Location Counter.
* LONG(EXPRESSION): Section Contents.
* M and K integer suffixes: Integers.
* machine architecture, output: Other Commands.
* MEMORY: MEMORY.
* memory region attributes: MEMORY.
* memory regions and sections: Section Options.
* MRI compatibility: MRI.
* names: Symbols.
* naming memory regions: MEMORY.
* naming output sections: Section Definition.
* naming the output file: Invocation.
* naming the output file: Other Commands.
* negative integers: Integers.
* NEXT(EXP): Built-ins.
* NMAGIC: Invocation.
* NOFLOAT: Other Commands.
* NOLOAD: Section Options.
* Non constant expression: Assignment.
* o =: MEMORY.
* object file management: BFD.
* object files: Invocation.
* octal integers: Integers.
* OMAGIC: Invocation.
* opening object files: BFD outline.
* Operators for arithmetic: Operators.
* options: Invocation.
* org =: MEMORY.
* ORIGIN =: MEMORY.
* OUTPUT ( FILENAME ): Other Commands.
* output file after errors: Invocation.
* output file layout: Scripts.
* OUTPUT_ARCH ( BFDNAME ): Other Commands.
* OUTPUT_FORMAT ( BFDNAME ): Other Commands.
* partial link: Invocation.
* path for libraries: Other Commands.
* precedence in expressions: Operators.
* prevent unnecessary loading: Section Options.
* quoted symbol names: Symbols.
* read-only text: Invocation.
* read/write from cmd line: Invocation.
* regions of memory: MEMORY.
* relaxing addressing modes: Invocation.
* relocatable and absolute symbols: Assignment.
* relocatable output: Invocation.
* requirements for BFD: BFD.
* rounding up location counter: Built-ins.
* scaled integers: Integers.
* script files: Invocation.
* scripts on command line: Invocation.
* search directory, from cmd line: Invocation.
* search path, libraries: Other Commands.
* SEARCH_DIR ( PATH ): Other Commands.
* section address: Built-ins.
* section address: Section Options.
* section alignment: Section Options.
* section definition: Section Definition.
* section defn, full syntax: Section Options.
* section fill pattern: Section Options.
* section size: Built-ins.
* section start: Section Options.
* section, assigning to memory region: Section Options.
* SECTIONS: SECTIONS.
* segment origins, cmd line: Invocation.
* semicolon: Assignment.
* SHORT(EXPRESSION): Section Contents.
* SIZEOF(SECTION): Built-ins.
* sizeof_headers: Built-ins.
* SIZEOF_HEADERS: Built-ins.
* standard Unix system: Invocation.
* start address, section: Section Options.
* start of execution: Entry Point.
* STARTUP ( FILENAME ): Other Commands.
* strip all symbols: Invocation.
* strip debugger symbols: Invocation.
* suffixes for integers: Integers.
* symbol defaults: Built-ins.
* symbol definition, scripts: Assignment.
* symbol names: Symbols.
* symbol tracing: Invocation.
* symbol-only input: Invocation.
* symbols, from command line: Invocation.
* symbols, relocatable and absolute: Assignment.
* synthesizing linker: Invocation.
* TARGET ( FORMAT ): Other Commands.
* unallocated address, next: Built-ins.
* undefined symbol: Invocation.
* uninitialized data: Section Contents.
* unspecified memory: Section Contents.
* variables, defining: Assignment.
* verbose: Invocation.
* version: Invocation.
* what is this?: Overview.
* [ SECTIONS ]: Section Contents.